import 'dart:io';
import 'dart:typed_data';

import '../async/stream/file.dart';

void padLeftTest() {
  String str = '12';
  print(str.padLeft(5, '0'));
  print(str.padRight(5, '0'));
}

void splitTest() {
  var str = Directory.current.path;
  print(str);
  var l = str.split('\\');
  for (var value in l) {
    print(value);
  }

  var split = '192.168.0.7'.split('.');
  print(split);
  print(split[3]);
  var ips = List<String>.empty(growable: true);
  for (var i = 254; i > 0; i--) {
    ips.add('192.168.0.$i');
  }

  ips.sort((a, b) {
    return int.parse(a.split('.')[3]).compareTo(int.parse(b.split('.')[3]));
  });
  print(ips);
  ips.sort((a, b) {
    return int.parse(b.split('.')[3]).compareTo(int.parse(a.split('.')[3]));
  });
  print(ips);
}

void lastIndexOfTest() {
  var str = '/c/b/e/a.html';
  print(str.lastIndexOf('.'));
  print(str.substring(str.lastIndexOf('.')));
  print(str.substring(str.lastIndexOf('/')));
  print(Platform.pathSeparator);
}

Uint8List convertStringToUint8List(String str) {
  final List<int> codeUnits = str.codeUnits;
  final Uint8List unit8List = Uint8List.fromList(codeUnits);

  return unit8List;
}

String convertUint8ListToString(Uint8List uint8list) {
  return String.fromCharCodes(uint8list);
}

main() {
  // splitTest();
  // lastIndexOfTest();
  // padLeftTest();

  print(convertStringToUint8List("hello"));
  print(convertUint8ListToString(Uint8List.fromList([104, 101, 108, 108, 111])));
}
